<template name="ThreadList">
  <ul class="list-group threads">
    {{#unless threads.count}}
      <li class="list-group-item thread text-muted">{{_ 'app_no_record'}}</li>
    {{/unless}}
    {{#each threads}}
      {{> ThreadListItemTemplate}}
    {{/each}}
    {{#if ready}}
      {{#if nextPath}}
        <a href="{{nextPath}}" class="list-group-item text-center text-muted thread small">
          {{_ "paginate_load_more"}}
        </a>
      {{/if}}
    {{else}}
      <span class="list-group-item text-center text-muted thread small"><i class="fa fa-spinner fa-spin"></i></span>
    {{/if}}
  </ul>
</template>

<template name="ThreadListItemTemplate">
  <a href="{{threadPath}}" class="list-group-item clearfix thread" id="{{_id}}">
    {{> Template.dynamic template=(threadListTemplate this)}}
  </a>
</template>

<template name="ThreadListItem">
  <div class="thread-icon {{#unless read}}unread{{/unless}}">
    <button type="button" class="avatar"><i class="{{threadIcon this}}"></i></button>
    <span class="red-point"></span>
  </div>
  <div class="thread-title">
    <small class="pull-right text-muted">{{formatSimpleDate updatedAt}}</small>
    <div class="thread-subject text-ellipsis">{{threadTitle this}}</div>
    <div class="message-summary text-ellipsis text-muted">
      {{#if lastMessage}}
        {{#if lastMessage.user}}
          {{#unless isMe lastMessage.user}}{{lastMessage.user.name}}: {{/unless}}
        {{/if}}
        {{{lastMessage.localizedSummary}}}
      {{/if}}
    </div>
  </div>
</template>

<template name="SimpleThreadListItem">
  <div class="thread-icon">
    <button type="button" class="avatar"><i class="{{threadIcon this}}"></i></button>
  </div>
  <div class="thread-title">
    <div class="thread-subject text-ellipsis">{{threadTitle this}}</div>
  </div>
</template>
